package ro.pub.cs.dfsa.server.connection;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import ro.pub.cs.dfsa.client.connection.AbstractClientConnection;
import ro.pub.cs.dfsa.client.connection.TCPClientConnection;

public class TCPServerConnection extends AbstractServerConnection {
    
    private ServerSocket serverSocket;
    private ObjectOutputStream oos;
    private ObjectInputStream ois;
    
    public TCPServerConnection() {
    }
    
    @Override
    public void createListener() throws IOException {
    	serverSocket = new ServerSocket(serverPort);
    }
    
    @Override
    public AbstractClientConnection getClient() throws IOException {
    	Socket clientSocket = serverSocket.accept();    	
    	TCPClientConnection connection = new TCPClientConnection(clientSocket);
    	return connection;
    }
    
    @Override
    public void close() throws IOException {
    	serverSocket.close();
    }
}
